package com.Jano.dao.Impl;

import com.Jano.dao.ProductDao;
import com.Jano.dto.ProductPageRow;
import com.Jano.dto.ProductPrice;
import com.Jano.entity.Product;
import org.junit.Test;

import java.util.List;

/**
 * description: ProductDaoImpl <br>
 * date: 2022/6/10 6:39 PM <br>
 * author: zoumaoji <br>
 * version: 1.0 <br>
 */
public class ProductDaoImpl extends AbstractDaoImpl implements ProductDao {
    @Override
    public void updateClickCount(Integer productId, Integer clickCount) {
        update("update product set clickcount=? where id=?;",new Object[]{clickCount,productId});
    }

    @Override
    public ProductPrice selectPriceByProductId(Integer productId) {
        return queryForObject("select id productId,price from product where id=?",ProductPrice.class,new Object[]{productId});
    }

    @Override
    public Product selectProductByProductId(Integer productId) {
        return queryForObject("select id productId,title,sellpoint sellPoint,price,clickcount clickCount,image,cid,created from product where id=?",Product.class,new Object[]{productId})  ;
    }

    @Override
    public List<ProductPageRow> selectProductPageRows(Integer cid, Integer start, Integer end) {
        return queryForList("select id productId,title,sellpoint sellPoint,price,clickcount clickCount,image,cid,created from product where cid=? limit ?,?",ProductPageRow.class,new Object[]{cid,start,end});
    }

    @Test
    public void test(){
        System.out.println(selectProductPageRows(560, 0, 10));
    }
}

